Skip to main content

All Questions

8votes
3answers
2kviews

Is set of integers closed under the operation of subtraction?

I was working on a problem, but my solution did not pass the time limit test. Problem Let's say a set of integers is closed under the operation of subtraction if for two distinct elements of this set ...
user27571279's user avatar
2votes
1answer
763views

Traveling Salesman Problem for visiting cities

Implement TSP problem using best first algorithm (so it will be backtracking, branch-and-bound, and best-first). Since you are looking for a cycle, the start/finish city is not important. Therefore we ...
Ruiru's user avatar
4votes
2answers
596views

O(nlogn) Lexicographically minimal rotation code but tle on this particular case

Based on a small suggestion here , this code tries to find lexicographically minimal rotation (question) by successively comparing two adjacent substrings in the very left , that can potentially give ...
Aryaman 's user avatar
2votes
2answers
98views

For two sequences N and M, display counts of elements n from N below each m from M up to the first n above m

A school's task: There are two sequences n_tab and m_tab. For every element m in m_tab ...
Szyszka947's user avatar
2votes
2answers
800views

Subarrays with length

You are given an array A of length N (where N is as large as 2×105). All elements of the array are positive integers less than or equal to N. Determine the count of subarrays (contiguous subsequences) ...
Vaibhav Vishal Singh's user avatar
3votes
1answer
3kviews

Recursive solution of ordered Coin Combinations II (CSES)

Question Link Consider a money system consisting of n coins. Each coin has a positive integer value. Your task is to calculate the number of distinct ordered ways you can produce a money sum x using ...
randomUser's user avatar
0votes
2answers
179views

Count the number of arithmetic progressions within a sequence

I have some problems with code for my classes. Even though it works correctly, I run out of time for half of the examples. Here's the task (I really did my best trying to translate it): You have a ...
amdlaihfgan's user avatar
2votes
1answer
2kviews

Geeks for Geeks: Trapping Rain Water Problem - time limit exceeded

Problem Statement: Given an array arr[] of N non-negative integers representing the height of blocks. If width of each block is 1, compute how much water can be trapped between the blocks during the ...
Neha Chaudhary's user avatar
2votes
0answers
120views

Monotonic stack - complexity analysis

I tried following the official solution of LC975 (https://leetcode.com/problems/odd-even-jump/), using a monotonic stack - i.e., I reimplemented their solution (Approach 1) from python in C++. TLDR ...
Mircea's user avatar
-2votes
1answer
149views

How to work in linear time with DFS

I tried a Hackerrank problem and it gives me a successful message, it works fine for Hackerrank criteria. The member states of the UN are planning to send 2 people to the moon. They want them to be ...
rusiru thushara's user avatar
2votes
2answers
169views

Designing a stack such that getMin() is both constant time and constant space

I'm attempting the SpecialStack problem on GeeksforGeeks. Design a data-structure SpecialStack (using the STL of stack) that supports all the stack operations like push(), pop(), isEmpty(), ...
user avatar
4votes
1answer
311views

Find positive integer with a minimum number of binary 1's such that its bitwise AND with all array elements is not 0

Task You have an array of positive integers. Your task is to find an integer x such that the following are true: Bitwise AND between ...
Anatolii's user avatar
1vote
0answers
304views

Algorithm for building a string by appending and cloning substrings [closed]

I have a problem where I need to construct a given string from scratch for a minimum cost by either: Appending a new character for a cost A Appending a substring of my existing string for a cost B ...
esperski's user avatar
2votes
1answer
390views

Find the largest sum of the GCD and LCM of two numbers in a range

The program is supposed to get one number n as input, and output the max value of gcd + lcm of two numbers that range from 1 to n. For example, if n == 3, the answer is 7 because gcd(3,2) == 1 and ...
programmer45's user avatar
1vote
1answer
106views

Check if is it possible to get to a point that is presented by a number [closed]

Problem description from an Iranian online course, translated with the help of Google Translate: Tired of coding, Mehdi has gone on to his childhood games. But because he doesn't know who to play ...
Arshia R's user avatar

153050per page
close